package com.wy2.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.wy2.entity.Module;
import com.wy2.entity.Student;
import com.wy2.entity.User;
import com.wy2.mapper.StudentMapper;
import com.wy2.service.StudentService;
import com.wy2.service.UserService;
import com.wy2.util.FenyeUtil;

@RequestMapping("student")
@RestController
@CrossOrigin
public class StudentController {


	@Autowired
	private StudentService studentservice;
	
	@Autowired
	private StudentMapper studentMapper; 
	
	@Autowired
	private UserService us;
	//分页查询的方法
	@GetMapping
	public FenyeUtil<Student> getAll( FenyeUtil<Student> fenye,Student student){//student是实体类
		//把查询所有的参数传到分页工具类
		fenye.setT(student);
		//返回查询的数据
		return studentservice.getAll(fenye);
		
	}
	
	//添加学生信息
	@RequestMapping("/addstudent")
	public Integer addMod(Student s) {
		// s 添加的实体
		return studentservice.addStudent(s);//返回添加的数据
	}
	
	@RequestMapping("/updstudent")
	public Integer updMod(Student s) {
		return studentservice.updStudent(s);
	}
	//删除学生信息
	@RequestMapping("/delstudent")
	public Integer delMod(Integer sid) {
		//sid就是获取的前台传过来的学生id
		System.out.println("---id"+sid);
		return studentservice.delStudent(sid);
	}
	
	/**
	 * 软删
	 * @param sid
	 * @return
	 */
	@RequestMapping("/updateExt")
	public Integer updateExt(Integer sid) {
		System.out.println(sid+"-------");
		return studentservice.updateExt(sid);
	}
	
	@RequestMapping("/findByExt")
	public FenyeUtil<Student> findByExt(FenyeUtil<Student> fenye,Integer page){
		fenye.setPage(page);
		return studentservice.findByExt(fenye);
	}
	
	@RequestMapping("/hy")
	public Integer StuExt(Integer sid,String ext) {
		return studentservice.stuExt(sid,ext);
	}
	
	@RequestMapping("/getZXS")
	public Object getZXS() {
		return studentMapper.getZXS();
	}
	
	@RequestMapping("/getZXSFP")
	public Object getZXSFP() {
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		return studentMapper.getZXSFP(sdf.format(new Date()));
	}
	/**
	 * 对学生进行手动分配
	 * @param zxsname
	 * @param zxid
	 * @param ids
	 * @return
	 */
	@RequestMapping("/upFP")
	public Integer upFP(String zxsname,String zxid,String ids) {
		System.out.println(ids+"-------");
		return studentservice.upFP(zxsname,zxid,ids);
	}
	/**
	 * 自动分配
	 * @param zxsname
	 * @param zxid
	 * @param ids
	 * @return
	 */
	@RequestMapping("/upZDFP")
	public Integer upZDFP(String zxsname , String zxid ,Integer ids) {
		return studentservice.upZDFP(zxsname,zxid,ids);
	}
	/**
	 * 获取未分配的学生
	 * @param zxsname
	 * @return
	 */
	@RequestMapping("/getAllWFP")
	public List<Student> getAllWFP(String zxsname) {
		return studentMapper.getAllWFP(zxsname);
	}
	
	/**
	 * 获取跟踪新增里学生的下拉单
	 * @param fenye
	 * @param stu
	 * @return
	 */
	@RequestMapping("/getSname")
	public FenyeUtil<Student> getStuSname(FenyeUtil<Student> fenye,Student stu){
		fenye.setT(stu);
		fenye = studentservice.getSname(fenye);
		return fenye;
	}
	
	
}
